package com.twb.quartz.listener;

import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.twb.quartz.service.ITwbQuartzJobService;

/** 
 * @ClassName TwbQuartzRunner 
 * @Description 定时任务启动类
 * @author DSY
 * @date 2019年10月28日 下午9:02:22 
 */ 
@Component
public class TwbQuartzRunner implements CommandLineRunner {

	private final Logger logger = LoggerFactory.getLogger(TwbQuartzRunner.class);
	@Autowired
	ITwbQuartzJobService twQuartzJobService;
	@Value("${twb.quartz.enabled}")
	private Boolean enabled;
	@Override
	public void run(String... args) throws Exception {
		// TODO Auto-generated method stub
		if(enabled) {
			try {
				twQuartzJobService.startAllJobs();
				logger.debug("定时任务启动成功");
			} catch (SchedulerException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				logger.debug("定时任务启动失败");
			}
		}
	}
}
